-- @owner: @zhanghuan96
-- @date: 2025/4/8
-- @testpoint: @@spid函数查询结果插入表中
@conn PrimaryDbDmode;
--step1:建表;expect:成功
drop table if exists t_rowcount0008;
CREATE TABLE t_rowcount0008 (
    log_id SERIAL PRIMARY KEY,
    pid BIGINT NOT NULL,
    log_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
--step2:创建函数;expect:成功
drop function if exists func_rowcount0008;
CREATE OR REPLACE FUNCTION func_rowcount0008()
RETURNS VOID
LANGUAGE plpgsql
AS $$
DECLARE
    current_pid BIGINT;
BEGIN
    current_pid := @@spid;
    INSERT INTO t_rowcount0008 (pid) VALUES (current_pid);
    RAISE NOTICE 'NOTICE:已记录进程ID: %', current_pid;
END;
$$;
/
--step3:调用函数;expect:成功
SELECT func_rowcount0008();
--step4:查询表;expect:pid列插入会话id
SELECT * FROM t_rowcount0008;
--step5:清理环境;expect:成功
drop table if exists t_rowcount0008;
drop function if exists func_rowcount0008;